package com.example.a10928.weifriend.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.constraint.ConstraintLayout;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RadioButton;
import android.widget.TextView;

import com.example.a10928.weifriend.R;

public class TextRadioLayout extends ConstraintLayout {

    private TextView tv;
    private RadioButton radio;

    public TextRadioLayout(Context context) {
        super(context);
    }

    public TextRadioLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        ConstraintLayout.inflate(context, R.layout.layout_text_radio, this);
        tv = findViewById(R.id.title);
        radio = findViewById(R.id.radio);

        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.TextRadioLayout);
        boolean isCheck = typedArray.getBoolean(R.styleable.TextRadioLayout_TextRadioLayout_check, false);
        String title = typedArray.getString(R.styleable.TextRadioLayout_TextRadioLayout_tv);
        if (title == null) {
            title = "";
        }
        typedArray.recycle();//释放资源
        tv.setText(title);
        radio.setChecked(isCheck);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return true;
    }

    public void setChecked(boolean isCheck) {
        radio.setChecked(isCheck);
    }

    public void setTitle(String title) {
        tv.setText(title);
    }
}
